using MCTS;
using System.Collections.Generic;
using UnityEngine;

namespace Gobang
{
    public class InternalPredictionLaucher : MonoBehaviour, IPredictionLaucher
    {
        [SerializeField]
        private MonteCarloTree tree;
        private ChessboardMono chessboard;

        public bool IsRunning => isRunning;
        private bool isRunning;

        public int nodePerFrame;
        public int mockPerNode;

        public void Restart()
        {
            tree = new MonteCarloTree(new ChessboardState(chessboard));
            isRunning = true;
        }

        public void Stop()
        {
            isRunning = false;
        }

        private void Awake()
        {
            chessboard = ChessboardMono.FindInstance();
        }

        private void Update()
        {
            if (!isRunning)
                return;

            for (int i = 0; i < nodePerFrame; i++)
            {
                tree.Mock(mockPerNode);
            }
        }

        public void GetPrediction(List<PredictionPointData> ret, int count)
        {
            tree.GetPrediction(ret, count);
        }
    }
}